package com.taiji.workOrder.service.impl;

import com.taiji.common.utils.SecurityUtils;
import com.taiji.workOrder.domain.Message;
import com.taiji.workOrder.mapper.MessageMapper;
import com.taiji.workOrder.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author -1
 * @since 2023/07/06 9:59
 * description:
 */
@Service
public class MessageServiceImpl implements IMessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public List<Message> findMessageInfoByUserName(String username) {
        List<Message> messageInfoByUserName = messageMapper.findMessageInfoByUserName(username);
      /*  for (Message message : messageInfoByUserName) {
            updateMessageStatusById(message.getId());
        }*/
        return  messageInfoByUserName;
    }

    @Override
    public int updateMessageStatusById(String id) {

        messageMapper.updateMessageStatusById(id);
        return 0;
    }

    /**
     * 查询工单信息
     *
     * @param id 工单信息主键
     * @return 工单信息
     */
    @Override
    public Message selectMessageById(String id)
    {
        messageMapper.updateMessageStatusById(id);
        return messageMapper.selectMessageById(id);
    }

    /**
     * 查询工单信息列表
     *
     * @param message 工单信息
     * @return 工单信息
     */
    @Override
    public List<Message> selectMessageList(Message message)
    {
        String username = SecurityUtils.getUsername();
        message.setToName(username);
        return messageMapper.selectMessageList(message);
    }

    /**
     * 新增工单信息
     *
     * @param message 工单信息
     * @return 结果
     */
    @Override
    public int insertMessage(Message message)
    {
        return messageMapper.insertMessage(message);
    }

    /**
     * 修改工单信息
     *
     * @param message 工单信息
     * @return 结果
     */
    @Override
    public int updateMessage(Message message)
    {
        return messageMapper.updateMessage(message);
    }

    /**
     * 批量删除工单信息
     *
     * @param ids 需要删除的工单信息主键
     * @return 结果
     */
    @Override
    public int deleteMessageByIds(String[] ids)
    {
        return messageMapper.deleteMessageByIds(ids);
    }

    /**
     * 删除工单信息信息
     *
     * @param id 工单信息主键
     * @return 结果
     */
    @Override
    public int deleteMessageById(String id)
    {
        return messageMapper.deleteMessageById(id);
    }
}
